package com.itcast.datasource.druid;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.net.URL;
import java.sql.Connection;
import java.util.Properties;

/**
 * druid 的演示
 */
public class druidDemo {
    public static void main(String[] args) throws Exception {
        // 加载配置文件
        Properties p = new Properties();
        ClassLoader classLoader = druidDemo.class.getClassLoader();
        URL resource = classLoader.getResource("druid.properties");
        assert resource != null;
        p.load(new FileReader((resource.getPath())));

        // 获取连接池对象
        DataSource dataSource = DruidDataSourceFactory.createDataSource(p);

        // 获取连接对象
        Connection connection = dataSource.getConnection();

        System.out.println(connection);

    }
}
